home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HEDGE11.ZIP / HEDGE.C < prev    next >
Text File  |  1995-02-12  |  23KB  |  870 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. *  HEDGE.C                                                                   *
  4. *                                                                            *
  5. *  Copyright 1993-1995 Diana Gruber. All rights reserved.                    *
  6. *                                                                            *
  7. *  This program is copyrighted freeware, distributed with source code.       *
  8. *  Code is provided "as is" without any warranties. You may use portions     *
  9. *  of this code in your own programs as long as you do not use more than     *
  10. *  50% of the code in any one program.                                       *
  11. *                                                                            *
  12. *  This code is provided for instructional purposes. It requires Fastgraph   *
  13. *  or Fastgraph/Light to link.                                               *
  14. *                                                                            *
  15. *  For more information, including the compilation and linking commands for  *
  16. *  all supported compilers, please see the HEDGE.DOC file.                   *
  17. *                                                                            *
  18. \****************************************************************************/
  19.  
  20. #include "defs.h"
  21. #define NMAZES 7
  22.  
  23. /****************************************************************************\
  24. *                                                                            *
  25. *  main -- all functions are in alphabetical order except this one           *
  26. *                                                                            *
  27. \****************************************************************************/
  28.  
  29. void main()
  30. {
  31.    register int n;
  32.  
  33.    static char *maze_name[] =
  34.    {
  35.       "maze001.lev",
  36.       "maze002.lev",
  37.       "maze003.lev",
  38.       "maze004.lev",
  39.       "maze005.lev",
  40.       "maze006.lev",
  41.       "maze007.lev"
  42.    };
  43.  
  44.    /* open the attribute file and read the attributes */
  45.  
  46.    if ((tstream = fopen("hedge.att","rb")) == NULL)
  47.    {
  48.       sprintf(abort_string,"HEDGE.ATT not found.");
  49.       abort_game();
  50.    }
  51.    fread(attributes,sizeof(char),240,tstream);
  52.    fclose(tstream);
  53.  
  54.    /* initialize SVGA graphics */
  55.  
  56.    init_graphics();
  57.    fg_tcmask(1);
  58.  
  59.    intro_screen();
  60.  
  61.    /* load the dub diner file on the hidden page */
  62.  
  63.    fg_setpage(HIDDEN);
  64.    fg_erase();
  65.    fg_move(80,60);
  66.    fg_showpcx("DUBDINER.PCX",2);
  67.  
  68.    /* copy it to the logical page (EMS or XMS) */
  69.  
  70.    fg_copypage(HIDDEN,SPARE);
  71.  
  72.    /* display the maze file on the hidden page */
  73.  
  74.    fg_move(0,0);
  75.    fg_showpcx("HEDGE.PCX",1);
  76.  
  77.    fg_setpage(VISUAL);
  78.    fg_setcolor(0);
  79.    center_string("Please wait...",400,300);
  80.    fg_setcolor(7);
  81.    center_string("Press any key to continue.",400,300);
  82.    fg_waitkey();
  83.  
  84.    for (n = 0; n < NMAZES; n++)
  85.    {
  86.       fg_setrgb(7,63,63,63);
  87.       fg_setrgb(5,63,63,63);
  88.       fg_setrgb(2,63,63,63);
  89.       fg_mousevis(OFF);
  90.       fg_copypage(SPARE,VISUAL);
  91.  
  92.       load_maze(maze_name[n]);
  93.  
  94.       memset(visited,0,50*38);
  95.       memset(path,-1,2000);
  96.       path_index = 1;
  97.  
  98.       flushkey();
  99.       if (n == 0) help_window();
  100.  
  101.       fg_mousevis(ON);
  102.       run_maze();
  103.    }
  104.    quit_graphics();
  105. }
  106.  
  107. /****************************************************************************\
  108. *                                                                            *
  109. *  calc_truepath -- recursive algorithm to solve maze                        *
  110. *                                                                            *
  111. \****************************************************************************/
  112.  
  113. int calc_truepath(int i,int j)
  114. {
  115.    int tile,nexttile;
  116.    int attr,nextattr;
  117.    int x1,x2,y1,y2;
  118.    int found;
  119.    int index;
  120.    int stall_time;
  121.    int left,right,top,bottom;
  122.    int horizontal,vertical;
  123.    int nextcross;
  124.  
  125.    stall_time = clockspeed/4;
  126.    visited[i][j] = TRUE;
  127.    index = path_index;
  128.  
  129.    while(1)
  130.    {
  131.       fg_stall(stall_time);
  132.  
  133.       tile = layout[i][j];
  134.       attr = attributes[tile];
  135.       found = FALSE;
  136.  
  137.       x1 = i*16 + 6;
  138.       x2 = x1 + 4;
  139.       y1 = j*16 + 6;
  140.       y2 = y1 + 4;
  141.  
  142.       left       = attr&LEFT;
  143.       right      = attr&RIGHT;
  144.       top        = attr&TOP;
  145.       bottom     = attr&BOTTOM;
  146.       vertical   = attr&VERTICAL;
  147.       horizontal = attr&HORIZONTAL;
  148.  
  149.       if (horizontal || vertical)
  150.       {
  151.          if (path[index-1] == LEFT || path[index-1] == RIGHT)
  152.          {
  153.             top = FALSE; bottom = FALSE;
  154.          }
  155.          else if (path[index-1] == TOP || path[index-1] == BOTTOM)
  156.          {
  157.             left = FALSE; right = FALSE;
  158.          }
  159.       }
  160.  
  161.       /* check right */
  162.  
  163.       if (j < MAXCOLS-1 && !found && !(path[index-1] == LEFT))
  164.       {
  165.          nexttile = layout[i+1][j];
  166.          nextattr = attributes[nexttile];
  167.          nextcross = ((nextattr&VERTICAL) + (nextattr&HORIZONTAL));
  168.          if (!visited[i+1][j] || (nextcross && (visited[i+1][j] != HORIZONTAL)))
  169.          {
  170.             if (right && nextattr&LEFT)
  171.             {
  172.                found = TRUE;
  173.                path[index++] = RIGHT;
  174.                i++;
  175.                visited[i][j] = HORIZONTAL;
  176.                x2 = i*16 + 10;
  177.                if (vertical)
  178.                  x1 += 9;
  179.                if (nextattr&VERTICAL)
  180.                  x2 -= 9;
  181.             }
  182.          }
  183.       }
  184.  
  185.       /* check UP */
  186.  
  187.       if (j > 0 && !found && !(path[index-1] == BOTTOM))
  188.       {
  189.          nexttile = layout[i][j-1];
  190.          nextattr = attributes[nexttile];
  191.          nextcross = ((nextattr&VERTICAL) + (nextattr&HORIZONTAL));
  192.          if (!visited[i][j-1] || (nextcross && (visited[i][j-1] != VERTICAL)))
  193.          {
  194.             if (top && nextattr&BOTTOM)
  195.             {
  196.                found = TRUE;
  197.                path[index++] = TOP;
  198.                j--;
  199.                visited[i][j] = VERTICAL;
  200.                y1 = j*16 + 6;
  201.                if (nextattr&HORIZONTAL)
  202.                  y1 += 9;
  203.                if (horizontal)
  204.                  y2 -= 9;
  205.             }
  206.          }
  207.       }
  208.  
  209.       /* check down */
  210.  
  211.       if (j < MAXROWS-1 && !found && !(path[index-1] == TOP))
  212.       {
  213.          nexttile = layout[i][j+1];
  214.          nextattr = attributes[nexttile];
  215.          nextcross = ((nextattr&VERTICAL) + (nextattr&HORIZONTAL));
  216.          if (!visited[i][j+1] || (nextcross && (visited[i][j+1] != VERTICAL)))
  217.          {
  218.             if (bottom && nextattr&TOP)
  219.             {
  220.                found = TRUE;
  221.                path[index++] = BOTTOM;
  222.                j++;
  223.                visited[i][j] = VERTICAL;
  224.                y2 = j*16 + 10;
  225.                if (horizontal)
  226.                  y1 += 9;
  227.                if (nextattr&HORIZONTAL)
  228.                  y2 -= 9;
  229.             }
  230.          }
  231.       }
  232.  
  233.       /* check left */
  234.  
  235.       if (i > 0 && !found && !(path[index-1] == RIGHT))
  236.       {
  237.          nexttile = layout[i-1][j];
  238.          nextattr = attributes[nexttile];
  239.          nextcross = ((nextattr&VERTICAL) + (nextattr&HORIZONTAL));
  240.          if (!visited[i-1][j] || (nextcross && (visited[i-1][j] != HORIZONTAL)))
  241.          {
  242.             if (left && nextattr&RIGHT)
  243.             {
  244.                found = TRUE;
  245.                path[index++] = LEFT;
  246.                i--;
  247.                visited[i][j] = HORIZONTAL;
  248.                x1 = i*16 + 6;
  249.                if (nextattr&VERTICAL)
  250.                  x1 += 9;
  251.                if (vertical)
  252.                  x2 -= 9;
  253.             }
  254.          }
  255.       }
  256.  
  257.       /* adjacent tile found */
  258.  
  259.       if (found)
  260.       {
  261.          fg_setcolor(0);
  262.          fg_rect(x1,x2,y1,y2);
  263.          if (is_a_vertex(nexttile))
  264.          {
  265.             path_index = index;
  266.  
  267.             /* You are at a vertex, do a recursive function call */
  268.  
  269.             if (calc_truepath(i,j))
  270.                 return(TRUE);
  271.  
  272.             /* try again (vertices may have 2 or 3 paths) */
  273.  
  274.             else
  275.             {
  276.                unfill_path(i,j,index);
  277.                path_index = index;
  278.                if (calc_truepath(i,j))
  279.                    return(TRUE);
  280.                else
  281.                {
  282.                    /* you are on the wrong path -- backtrack */
  283.  
  284.                    unfill_path(i,j,index);
  285.                }
  286.             }
  287.          }
  288.       }
  289.  
  290.       /* reached a dead end */
  291.  
  292.       else
  293.       {
  294.          n_nodes = index;
  295.          return(FALSE);
  296.       }
  297.  
  298.       /* reached end of path -- maze solved! */
  299.  
  300.       if (test_bit(nextattr,7) || test_bit(attr,7))
  301.       {
  302.          n_nodes = index;
  303.          return(TRUE);
  304.       }
  305.    }
  306. }
  307.  
  308. /****************************************************************************\
  309. *                                                                            *
  310. *  help_window -- press F1 for popup help                                    *
  311. *                                                                            *
  312. \****************************************************************************/
  313.  
  314. void help_window()
  315. {
  316.    fg_mousevis(OFF);
  317.    fg_transfer(200,599,200,389,200,389,VISUAL,HIDDEN);
  318.  
  319.    fg_setcolor(7);
  320.    fg_rect(200,599,200,389);
  321.    fg_setcolor(1);
  322.    fg_box(200,599,200,389);
  323.    center_string("Help Screen",400,220);
  324.  
  325.    fg_setcolor(0);
  326.    put_string("Use the mouse to maneuver through the maze",230,240);
  327.    put_string("from the blue square to the red square.",230,256);
  328.  
  329.    put_string("F1:",260,280);
  330.    put_string("Help",320,280);
  331.  
  332.    put_string("N:",260,300);
  333.    put_string("Next Maze",320,300);
  334.  
  335.    put_string("R:",260,320);
  336.    put_string("Recursive Solution",320,320);
  337.  
  338.    put_string("C:",260,340);
  339.    put_string("Cheat mode",320,340);
  340.  
  341.    put_string("Esc:",260,360);
  342.    put_string("Exit",320,360);
  343.  
  344.    fg_setcolor(1);
  345.    center_string("Press any key to continue",400,380);
  346.  
  347.    fg_waitkey();
  348.    fg_transfer(200,599,200,389,200,389,HIDDEN,VISUAL);
  349.    fg_mousevis(ON);
  350. }
  351.  
  352. /****************************************************************************\
  353. *                                                                            *
  354. *  intro_screen -- display copyright information, etc.                       *
  355. *                                                                            *
  356. \****************************************************************************/
  357.  
  358. void intro_screen()
  359. {
  360.    fg_mousevis(OFF);
  361.    fg_setcolor(7);
  362.    center_string("Hedge Row",400,84);
  363.    center_string("Copyright 1993-1995 Diana Gruber. All rights reserved.",400,116);
  364.    center_string("Written with Fastgraph programmer's graphics library.",400,148);
  365.    center_string("Beta version -- source code available.",400,180);
  366.    center_string("Please wait...",400,300);
  367. }
  368.  
  369. /****************************************************************************\
  370. *                                                                            *
  371. *  is_a_vertex -- check a tile to see if it is a vertex                      *
  372. *                                                                            *
  373. \****************************************************************************/
  374.  
  375. int is_a_vertex(int tile)
  376. {
  377.    int attr;
  378.    int left,right,top,bottom;
  379.    int horizontal,vertical;
  380.  
  381.    attr = attributes[tile];
  382.  
  383.    left   = ((attr&LEFT)>0);
  384.    right  = ((attr&RIGHT)>0);
  385.    top    = ((attr&TOP)>0);
  386.    bottom = ((attr&BOTTOM)>0);
  387.  
  388.    vertical   = attr&VERTICAL;
  389.    horizontal = attr&HORIZONTAL;
  390.  
  391.    if (vertical || horizontal)
  392.       return(FALSE);
  393.  
  394.    if (left+right+top+bottom >= 3)
  395.       return(TRUE);
  396.    else
  397.       return(FALSE);
  398. }
  399.  
  400. /****************************************************************************\
  401. *                                                                            *
  402. *  load_maze -- read maze information from a file                            *
  403. *                                                                            *
  404. \****************************************************************************/
  405.  
  406. void load_maze(char *mazename)
  407. {
  408.    register int i,j;
  409.    short nrows,ncols;
  410.    int x,y,tile;
  411.    char buffer[100];
  412.  
  413.    /* open the maze file and read the maze data */
  414.  
  415.    if ((tstream = fopen(mazename,"rb")) == NULL)
  416.    {
  417.       sprintf(abort_string,"%s not found.",mazename);
  418.       abort_game();
  419.    }
  420.  
  421.    fread(&ncols,sizeof(short),1,tstream);
  422.    fread(&nrows,sizeof(short),1,tstream);
  423.  
  424.    for (i = 0; i < 50; i++)
  425.    {
  426.       fread(buffer,sizeof(char),nrows,tstream);
  427.       memcpy(&layout[i][0],buffer,37);
  428.    }
  429.    fclose(tstream);
  430.  
  431.    /* display the maze tiles */
  432.  
  433.    fg_mousevis(OFF);
  434.    for (i = 0; i < ncols; i++)
  435.    {
  436.       for (j = 0; j < nrows; j++)
  437.       {
  438.          x = i*16;
  439.          y = j*16+15;
  440.          tile = layout[i][j];
  441.          put_tile(tile,x,y);
  442.       }
  443.    }
  444. }
  445.  
  446. /****************************************************************************\
  447. *                                                                            *
  448. *  put_tile -- transfer a maze tile from the hidden page to the visual page  *
  449. *                                                                            *
  450. \****************************************************************************/
  451.  
  452. void put_tile(int tile,int x,int y)
  453. {
  454.    int x1,x2,y1,y2;
  455.  
  456.    x1 = (tile%20) * 16;
  457.    x2 = x1+15;
  458.    y1 = (tile/20) * 16;
  459.    y2 = y1+15;
  460.  
  461.    fg_tcxfer(x1,x2,y1,y2,x,y,HIDDEN,VISUAL);
  462. }
  463.  
  464. /****************************************************************************\
  465. *                                                                            *
  466. *  run_maze -- this is where all the user interaction happens                *
  467. *                                                                            *
  468. \****************************************************************************/
  469.  
  470. void run_maze()
  471. {
  472.    unsigned char key,aux;
  473.    register int i,j;
  474.    int solution;
  475.    int xmouse,ymouse,buttons;
  476.    int tile,attr;
  477.    int x1,x2,x3,x4;
  478.    int y1,y2,y3,y4;
  479.    int xmin,xmax,ymin,ymax;
  480.    int old_xmin,old_xmax,old_ymin,old_ymax;
  481.    int old_xmouse,old_ymouse;
  482.    int left,right,top,bottom;
  483.    int horizontal,vertical;
  484.    int direction;
  485.    int old_i,old_j;
  486.    int norect;
  487.    char old_tile, old_attr;
  488.  
  489.    fg_mousevis(ON);
  490.  
  491.    old_xmin = 0; old_xmax = 0;
  492.    old_ymin = 0; old_ymax = 0;
  493.  
  494.    solution = FALSE;
  495.  
  496.    fg_mouselim(0,799,0,599);
  497.    fg_mousemov(20,8);
  498.    old_i = 1;
  499.    old_j = 0;
  500.    direction = VERTICAL;
  501.  
  502.    fg_mousepos(&old_xmouse,&old_ymouse,&buttons);
  503.  
  504.    while(1)
  505.    {
  506.       fg_intkey(&key,&aux);
  507.       if (key == 27)
  508.          quit_graphics();
  509.       else if (key == 'n' || key == 'N')
  510.          return;
  511.       else if (aux == F1)
  512.          help_window();
  513.       else if (key == 'r' || key == 'R')
  514.       {
  515.          fg_mousevis(OFF);
  516.          calc_truepath(1,0);
  517.          flushkey();
  518.          fg_getkey(&key,&aux);
  519.          if (key == 27)
  520.             quit_graphics();
  521.          return;
  522.       }
  523.       else if (key == 'c' || key == 'C')
  524.       {
  525.          solution = !solution;
  526.          if (solution)
  527.             fg_setrgb(7,25,25,63);
  528.          else
  529.             fg_setrgb(7,63,63,63);
  530.       }
  531.  
  532.       fg_mousepos(&xmouse,&ymouse,&buttons);
  533.       i = xmouse/16;
  534.       j = ymouse/16;
  535.  
  536.       if (i != old_i)
  537.          direction = HORIZONTAL;
  538.       else if (j != old_j)
  539.          direction = VERTICAL;
  540.  
  541.       tile = layout[i][j];
  542.       attr = attributes[tile];
  543.  
  544.       x1 = i*16-1;
  545.       x2 = x1+7;
  546.       x3 = x1+11;
  547.       x4 = MIN(x1+17,799);
  548.       x1 = MAX(i*16-1,0);
  549.  
  550.       y1 = j*16-1;
  551.       y2 = y1+7;
  552.       y3 = y1+11;
  553.       y4 = MIN(y1+17,599);
  554.       y1 = MAX(j*16-1,0);
  555.  
  556.       left       = attr&LEFT;
  557.       right      = attr&RIGHT;
  558.       top        = attr&TOP;
  559.       bottom     = attr&BOTTOM;
  560.       vertical   = attr&VERTICAL;
  561.       horizontal = attr&HORIZONTAL;
  562.  
  563.       if (horizontal || vertical)
  564.       {
  565.          if (direction == HORIZONTAL)
  566.          {
  567.             top = FALSE; bottom = FALSE;
  568.          }
  569.          else if (direction == VERTICAL)
  570.          {
  571.             left = FALSE; right = FALSE;
  572.          }
  573.       }
  574.  
  575.       /* calculate extents of mouse limits */
  576.  
  577.       if (right && xmouse > x2)
  578.       {
  579.          if (i == MAXCOLS-1 || !(attributes[layout[i+1][j]]&LEFT))
  580.             xmax = x3;
  581.          else
  582.             xmax = x4;
  583.       }
  584.       else
  585.          xmax = x3;
  586.  
  587.       if (left && xmouse < x3)
  588.       {
  589.          if (i == 0 || !(attributes[layout[i-1][j]]&RIGHT))
  590.             xmin = x2;
  591.          else
  592.             xmin = x1;
  593.       }
  594.       else
  595.          xmin = x2;
  596.  
  597.       if (bottom && ymouse > y2)
  598.       {
  599.          if (j == MAXROWS-1 || !(attributes[layout[i][j+1]]&TOP))
  600.             ymax = y3;
  601.          else
  602.             ymax = y4;
  603.       }
  604.       else
  605.          ymax = y3;
  606.  
  607.       if (top && ymouse < y3)
  608.       {
  609.          if (j == 0 || !(attributes[layout[i][j-1]]&BOTTOM))
  610.             ymin = y2;
  611.          else
  612.             ymin = y1;
  613.       }
  614.       else
  615.          ymin = y2;
  616.  
  617.       /* correct for diagonals - upper left */
  618.  
  619.       if (xmin == x1 && ymin == y1)
  620.       {
  621.          if (xmouse <= x2)
  622.             ymin = y2 - 3;
  623.          else
  624.             xmin = x2 - 3;
  625.       }
  626.  
  627.       /* upper right */
  628.  
  629.       if (xmax == x4 && ymin == y1)
  630.       {
  631.          if (xmouse >= x3)
  632.             ymin = y2 - 3;
  633.          else
  634.             xmax = x3 + 3;
  635.       }
  636.  
  637.       /* lower left */
  638.  
  639.       if (xmin == x1 && ymax == y4)
  640.       {
  641.          if (xmouse <= x2)
  642.             ymax = y3 + 3;
  643.          else
  644.             xmin = x2 - 3;
  645.       }
  646.  
  647.       /* lower right */
  648.  
  649.       if (xmax == x4 && ymax == y4)
  650.       {
  651.          if (xmouse >= x3)
  652.             ymax = y3 + 3;
  653.          else
  654.             xmax = x3 + 3;
  655.       }
  656.  
  657.       fg_mouselim(xmin,xmax,ymin,ymax);
  658.  
  659.       /* draw the path only if the mouse has moved*/
  660.  
  661.       if (xmouse != old_xmouse || ymouse != old_ymouse)
  662.       {
  663.  
  664.          /* going right */
  665.  
  666.          norect = FALSE;
  667.          if (old_i < i)
  668.          {
  669.             old_tile = layout[i-1][j];
  670.             old_attr = attributes[old_tile];
  671.             if (old_attr&VERTICAL)
  672.                xmin = x1;
  673.             else
  674.                xmin = x1 - 8;
  675.             if (vertical)
  676.                xmax = x2 - 5;
  677.             else
  678.                xmax = x3;
  679.          }
  680.  
  681.          /* going left */
  682.  
  683.          else if (old_i > i)
  684.          {
  685.             old_tile = layout[i+1][j];
  686.             old_attr = attributes[old_tile];
  687.             if (old_attr&VERTICAL)
  688.                xmax = x4 + 1;
  689.             else
  690.                xmax = x4 + 8;
  691.             if (vertical)
  692.                xmin = x3 + 5;
  693.             else
  694.                xmin = x2;
  695.          }
  696.  
  697.          /* no horizontal movement */
  698.  
  699.          else
  700.          {
  701.             xmin = x2;
  702.             xmax = x3;
  703.          }
  704.  
  705.  
  706.          /* going down */
  707.  
  708.          if (old_j < j)
  709.          {
  710.             old_tile = layout[i][j-1];
  711.             old_attr = attributes[old_tile];
  712.             if (old_attr&HORIZONTAL)
  713.                ymin = y1;
  714.             else
  715.                ymin = y1 - 8;
  716.             if (horizontal)
  717.                ymax = y2 - 5;
  718.             else
  719.                ymax = y3;
  720.          }
  721.  
  722.          /* going up */
  723.  
  724.          else if (old_j > j)
  725.          {
  726.             old_tile = layout[i][j+1];
  727.             old_attr = attributes[old_tile];
  728.             if (old_attr&HORIZONTAL)
  729.                ymax = y4 + 1;
  730.             else
  731.                ymax = y4 + 8;
  732.             if (horizontal)
  733.                ymin = y3 + 5;
  734.             else
  735.                ymin = y2;
  736.          }
  737.  
  738.          /* no vertical movement */
  739.  
  740.          else
  741.          {
  742.             ymin = y2;
  743.             ymax = y3;
  744.          }
  745.          if (i == old_i && j == old_j)
  746.             norect = TRUE;
  747.  
  748.          if (!norect)
  749.          {
  750.             fg_mousevis(OFF);
  751.             fg_setcolor(7);
  752.             if (old_xmin > 0) fg_rect(old_xmin,old_xmax,old_ymin,old_ymax);
  753.             fg_setcolor(3);
  754.             fg_rect(xmin,xmax,ymin,ymax);
  755.             fg_mousevis(ON);
  756.  
  757.             old_xmin = xmin; old_xmax = xmax;
  758.             old_ymin = ymin; old_ymax = ymax;
  759.          }
  760.       }
  761.  
  762.       old_xmouse = xmouse;
  763.       old_ymouse = ymouse;
  764.       old_i = i;
  765.       old_j = j;
  766.    }
  767. }
  768.  
  769. /****************************************************************************\
  770. *                                                                            *
  771. * test_bit -- used to check for tile attributes                              *
  772. *                                                                            *
  773. \****************************************************************************/
  774.  
  775. test_bit(int num,int bit)
  776. {
  777.    return((num >> bit) & 1);
  778. }
  779.  
  780. /****************************************************************************\
  781. *                                                                            *
  782. *  unfill_path -- change the color back to white                             *
  783. *                                                                            *
  784. \****************************************************************************/
  785.  
  786. int unfill_path(int i,int j,int n)
  787. {
  788.    int index;
  789.    int x1,x2,y1,y2;
  790.    int tile;
  791.    int attr;
  792.  
  793.    fg_setcolor(7);
  794.    for (index = n; index < n_nodes; index++)
  795.    {
  796.       x1 = i*16 + 6;
  797.       x2 = x1 + 4;
  798.       y1 = j*16 + 6;
  799.       y2 = y1 + 4;
  800.  
  801.       switch(path[index])
  802.       {
  803.          case LEFT:
  804.             tile = layout[i][j];
  805.             attr = attributes[tile];
  806.             if (attr&VERTICAL)
  807.               x2 -= 9;
  808.  
  809.             i--;
  810.             x1 = i*16 + 6;
  811.  
  812.             tile = layout[i][j];
  813.             attr = attributes[tile];
  814.             if (attr&VERTICAL)
  815.                x1 += 9;
  816.  
  817.             break;
  818.          case RIGHT:
  819.             tile = layout[i][j];
  820.             attr = attributes[tile];
  821.             if (attr&VERTICAL)
  822.                x1 += 9;
  823.  
  824.             i++;
  825.             x2 = i*16 + 10;
  826.  
  827.             tile = layout[i][j];
  828.             attr = attributes[tile];
  829.             if (attr&VERTICAL)
  830.                x2 -= 9;
  831.  
  832.             break;
  833.          case TOP:
  834.             tile = layout[i][j];
  835.             attr = attributes[tile];
  836.             if (attr&HORIZONTAL)
  837.               y2 -= 9;
  838.  
  839.             j--;
  840.             y1 = j*16 + 6;
  841.  
  842.             tile = layout[i][j];
  843.             attr = attributes[tile];
  844.             if (attr&HORIZONTAL)
  845.               y1 += 9;
  846.  
  847.             break;
  848.          case BOTTOM:
  849.             tile = layout[i][j];
  850.             attr = attributes[tile];
  851.             if (attr&HORIZONTAL)
  852.               y1 += 9;
  853.  
  854.             j++;
  855.             y2 = j*16 + 10;
  856.  
  857.             tile = layout[i][j];
  858.             attr = attributes[tile];
  859.             if (attr&HORIZONTAL)
  860.               y2 -= 9;
  861.  
  862.             break;
  863.          default:
  864.             return(FALSE);
  865.       }
  866.       fg_rect(x1,x2,y1,y2);
  867.    }
  868.    return(TRUE);
  869. }
  870.